<template>
  <el-row :xs="24">
    <header class="user-mgn-top" :xs="8">
      <div class="logo">
        <img src="@/assets/config_images/Group8.png" alt />
      </div>
      <div class="user-mgn-right" v-if="showfun">
        <p
          v-for="(item, idx) in topnav"
          :key="idx"
          @click="activeIdx(idx)"
          :class="nowidx === idx ? 'active':''"
        >
          <router-link :to="item.link">{{item.text}}</router-link>
        </p>
        <p>
          <svg-icon icon-class="inform"></svg-icon>
        </p>
        <el-dropdown class="avatar-container" trigger="click">
          <div class="header-img">
            <img src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" alt />
            <i class="el-icon-caret-bottom" />
          </div>
          <el-dropdown-menu slot="dropdown" class="user-dropdown">
            <router-link to="/manage/center">
              <el-dropdown-item>首页</el-dropdown-item>
            </router-link>
            <el-dropdown-item divided >
              <span style="display:block;" @click="logout">退出</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </header>
  </el-row>
</template>
<script>
export default {
  props: ["showfun", "topnav"],
  data() {
    return {
      nowidx: -1
    };
  },
  methods: {
    activeIdx(idx) {
      this.nowidx = idx;
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
};
</script>

<style lang="scss" scoped>
.logo {
  width: auto;
  height: 30px;
}
.user-mgn-top {
  width: 100%;
  height: 67px;
  position: fixed;
  padding: 0 50px;
  font-size: 16px;
  color: #353535;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 2px 5px -1px rgba(0, 0, 0, 0.1);
  z-index: 120;
}

.user-mgn-right {
  width: 360px;
  height: 67px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  p {
    cursor: pointer;
    flex: 1;
  }
  p.active {
    width: auto;
    height: 67px;
    line-height: 67px;
    color: #79b0ff;
  }
  .header-img {
    width: 38px;
    height: 38px;
    border-radius: 19;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>

